﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.ComponentModel;
using System.Data;

namespace PTExpress.Views
{
    /// <summary>
    /// Interaction logic for ucFooter.xaml
    /// </summary>
    public partial class ucFooter : UserControl
    {
        public DispatcherTimer dispatcherTimer = new DispatcherTimer();
        public ucFooter()
        {
            InitializeComponent();
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                DispatcherTimer dispatcherTimer = new DispatcherTimer();
                dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                dispatcherTimer.Start();
            }
        }

        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            tblDate.Text = App.M_LAN.Equals("V") ?
                ("Ngày " + DateTime.Now.Day + ", Tháng " + DateTime.Now.Month + ", Năm " + DateTime.Now.Year) :
                (DateTime.Now.ToLongDateString());
            tblTimer.Text = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
        }



        public string Server
        {
            get { return (string)GetValue(ServerProperty); }
            set { SetValue(ServerProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Server.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ServerProperty =
            DependencyProperty.Register("Server", typeof(string), typeof(ucFooter), new UIPropertyMetadata(""));



        public string DataBase
        {
            get { return (string)GetValue(DataBaseProperty); }
            set { SetValue(DataBaseProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DataBase.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DataBaseProperty =
            DependencyProperty.Register("DataBase", typeof(string), typeof(ucFooter), new UIPropertyMetadata(""));



        public string User
        {
            get { return (string)GetValue(UserProperty); }
            set { SetValue(UserProperty, value); }
        }

        // Using a DependencyProperty as the backing store for User.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty UserProperty =
            DependencyProperty.Register("User", typeof(string), typeof(ucFooter), new UIPropertyMetadata(""));

        public Delegate EventLogOut;
        private void LogOut_Click(object sender, RoutedEventArgs e)
        {
            EventLogOut.DynamicInvoke();
        }

        private void UserInfo_Click(object sender, RoutedEventArgs e)
        {
            //DataTable tb = ViewModels.NhanVienViewModel.GetNhanVienTheoUserName(App.UserName);
            //frmThemNhanVien frm = new frmThemNhanVien(tb, Command.Edit);
            //frm.Show();
        }

        private void UcFooter_Loaded(object sender, RoutedEventArgs e)
        {
            //dispatcherTimer.Start();
            if (User.ToUpper().Equals("ADMIN"))
                tblinfo.Visibility = System.Windows.Visibility.Collapsed;
        }
    }
}
